package com.muyu.product.service.impl;

import java.util.Date;
import java.util.List;

import com.muyu.common.core.utils.ObjUtils;
import com.muyu.common.security.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.muyu.product.mapper.BrandInfoMapper;
import com.muyu.product.domain.BrandInfo;
import com.muyu.product.service.BrandInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

/**
 * 品牌信息Service业务层处理
 *
 * @author DongZeLiang
 * @date 2024-02-27
 */
@Slf4j
@Service
public class BrandInfoServiceImpl extends ServiceImpl<BrandInfoMapper, BrandInfo>  implements BrandInfoService {

    /**
     * 查询品牌信息列表
     *
     * @param brandInfo 品牌信息
     * @return 品牌信息
     */
    @Override
    public List<BrandInfo> list(BrandInfo brandInfo) {
        LambdaQueryWrapper<BrandInfo> queryWrapper = new LambdaQueryWrapper<>();


        if (ObjUtils.notNull(brandInfo.getNam())){
            queryWrapper.like(BrandInfo::getNam, brandInfo.getNam());
        }

        if (ObjUtils.notNull(brandInfo.getLogo())){
            queryWrapper.eq(BrandInfo::getLogo, brandInfo.getLogo());
        }

        if (ObjUtils.notNull(brandInfo.getStart())){
            queryWrapper.eq(BrandInfo::getStart, brandInfo.getStart());
        }

        if (ObjUtils.notNull(brandInfo.getIntroduction())){
            queryWrapper.eq(BrandInfo::getIntroduction, brandInfo.getIntroduction());
        }

        return list(queryWrapper);
    }

    @Override
    public boolean save(BrandInfo entity) {
        entity.setCreateBy(SecurityUtils.getUsername());
        entity.setCreateTime(new Date());
        return super.save(entity);
    }

    @Override
    public boolean updateById(BrandInfo entity) {
        entity.setUpdateBy(SecurityUtils.getUsername());
        entity.setUpdateTime(new Date());
        return super.updateById(entity);
    }
}
